<?php 


	$uri = explode('?', $_SERVER['REQUEST_URI']);
	$page = explode('/', $uri[0]);

	$controller_name = $page[1] ? $page[1] : CONTROLLER_DEFAULT;
	$controller_path = mb_strtolower(ROOT . PATH_CONTROLLER . $controller_name . '_Controller.php');
	$controller_name .= '_Controller';

	$action_name = $page[2] ? $page[2] : ACTION_DEFAULT;
	$action_name .= '_action';


	$params = array();

	parse_str($uri[1], $params);
	
	if(isset($_REQUEST['debug'])){
		print('CONTROLLER:');
		print_r($controller);
		print('<br>ACTION:');
		print_r($action);
		print('<br>PARAMS:');
		print_r($params);
	}
	
	if(file_exists($controller_path)) {
		include_once($controller_path);
		$controller = new $controller_name($params);
		$action = $action_name;
		if(method_exists($controller, $action)) {
			$controller->$action();	
			exit();
		}
	}

	die('404. Страница не найдена');


?>